<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>
  Class: Mocha::StateMachine
  
    &mdash; Mocha 3.0.0-rc.2
  
</title>

  <link rel="stylesheet" href="../css/style.css" type="text/css" />

  <link rel="stylesheet" href="../css/common.css" type="text/css" />

<script type="text/javascript">
  pathId = "Mocha::StateMachine";
  relpath = '../';
</script>


  <script type="text/javascript" charset="utf-8" src="../js/jquery.js"></script>

  <script type="text/javascript" charset="utf-8" src="../js/app.js"></script>


  </head>
  <body>
    <div class="nav_wrap">
      <iframe id="nav" src="../class_list.html?1"></iframe>
      <div id="resizer"></div>
    </div>

    <div id="main" tabindex="-1">
      <div id="header">
        <div id="menu">
  
    <a href="../_index.html">Index (S)</a> &raquo;
    <span class='title'><span class='object_link'><a href="../Mocha.html" title="Mocha (module)">Mocha</a></span></span>
     &raquo; 
    <span class="title">StateMachine</span>
  
</div>

        <div id="search">
  
    <a class="full_list_link" id="class_list_link"
        href="../class_list.html">

        <svg width="24" height="24">
          <rect x="0" y="4" width="24" height="4" rx="1" ry="1"></rect>
          <rect x="0" y="12" width="24" height="4" rx="1" ry="1"></rect>
          <rect x="0" y="20" width="24" height="4" rx="1" ry="1"></rect>
        </svg>
    </a>
  
</div>
        <div class="clear"></div>
      </div>

      <div id="content"><h1>Class: Mocha::StateMachine
  
  
  
</h1>
<div class="box_info">
  
  <dl>
    <dt>Inherits:</dt>
    <dd>
      <span class="inheritName"><span class='object_link'>Object</span></span>
      
        <ul class="fullTree">
          <li><span class='object_link'>Object</span></li>
          
            <li class="next">Mocha::StateMachine</li>
          
        </ul>
        <a href="#" class="inheritanceTree">show all</a>
      
    </dd>
  </dl>
  

  
  
  
  
  

  

  
  <dl>
    <dt>Defined in:</dt>
    <dd>lib/mocha/state_machine.rb</dd>
  </dl>
  
</div>

<h2>Overview</h2><div class="docstring">
  <div class="discussion">
    
<p>A state machine that is used to constrain the order of invocations. An invocation can be constrained to occur when a state <span class='object_link'><a href="#is-instance_method" title="Mocha::StateMachine#is (method)">#is</a></span>, or <span class='object_link'><a href="#is_not-instance_method" title="Mocha::StateMachine#is_not (method)">#is_not</a></span>, active.</p>


  </div>
</div>
<div class="tags">
  

</div><h2>Defined Under Namespace</h2>
<p class="children">
  
    
  
    
      <strong class="classes">Classes:</strong> <span class='object_link'><a href="StateMachine/State.html" title="Mocha::StateMachine::State (class)">State</a></span>, <span class='object_link'><a href="StateMachine/StatePredicate.html" title="Mocha::StateMachine::StatePredicate (class)">StatePredicate</a></span>
    
  
</p>







  
    <h2>
      Instance Method Summary
      <small><a href="#" class="summary_toggle">collapse</a></small>
    </h2>

    <ul class="summary">
      
        <li class="public ">
  <span class="summary_signature">
    
      <a href="#become-instance_method" title="#become (instance method)">#<strong>become</strong>(next_state_name)  &#x21d2; Object </a>
    

    
  </span>
  
  
  
  
  
  
  

  
    <span class="summary_desc"><div class='inline'>
<p>Put the <span class='object_link'><a href="" title="Mocha::StateMachine (class)">StateMachine</a></span> into the <code>next_state_name</code>.</p>
</div></span>
  
</li>

      
        <li class="public ">
  <span class="summary_signature">
    
      <a href="#is-instance_method" title="#is (instance method)">#<strong>is</strong>(state_name)  &#x21d2; StatePredicate, State </a>
    

    
  </span>
  
  
  
  
  
  
  

  
    <span class="summary_desc"><div class='inline'>
<p>Provides mechanisms to (a) determine whether the <span class='object_link'><a href="" title="Mocha::StateMachine (class)">StateMachine</a></span> is in a given state; or (b) to change the <span class='object_link'><a href="" title="Mocha::StateMachine (class)">StateMachine</a></span> into the given state.</p>
</div></span>
  
</li>

      
        <li class="public ">
  <span class="summary_signature">
    
      <a href="#is_not-instance_method" title="#is_not (instance method)">#<strong>is_not</strong>(unexpected_state_name)  &#x21d2; StatePredicate </a>
    

    
  </span>
  
  
  
  
  
  
  

  
    <span class="summary_desc"><div class='inline'>
<p>Provides a mechanism to determine whether the <span class='object_link'><a href="" title="Mocha::StateMachine (class)">StateMachine</a></span> is <strong>not</strong> in the state specified by <code>unexpected_state_name</code> at some point in the future.</p>
</div></span>
  
</li>

      
        <li class="public ">
  <span class="summary_signature">
    
      <a href="#starts_as-instance_method" title="#starts_as (instance method)">#<strong>starts_as</strong>(initial_state_name)  &#x21d2; StateMachine </a>
    

    
  </span>
  
  
  
  
  
  
  

  
    <span class="summary_desc"><div class='inline'>
<p>Put the <span class='object_link'><a href="" title="Mocha::StateMachine (class)">StateMachine</a></span> into the state specified by <code>initial_state_name</code>.</p>
</div></span>
  
</li>

      
    </ul>
  



  <div id="instance_method_details" class="method_details_list">
    <h2>Instance Method Details</h2>

    
      <div class="method_details first">
  <h3 class="signature first" id="become-instance_method">
  
    #<strong>become</strong>(next_state_name)  &#x21d2; <tt><span class='object_link'>Object</span></tt> 
  

  

  
</h3><div class="docstring">
  <div class="discussion">
    
<p>Put the <span class='object_link'><a href="" title="Mocha::StateMachine (class)">Mocha::StateMachine</a></span> into the <code>next_state_name</code>.</p>


  </div>
</div>
<div class="tags">
  <p class="tag_title">Parameters:</p>
<ul class="param">
  
    <li>
      
        <span class='name'>next_state_name</span>
      
      
        <span class='type'>(<tt>String</tt>)</span>
      
      
      
        &mdash;
        <div class='inline'>
<p>name of new state</p>
</div>
      
    </li>
  
</ul>


</div><table class="source_code">
  <tr>
    <td>
      <pre class="lines">


60
61
62</pre>
    </td>
    <td>
      <pre class="code"><span class="info file"># File 'lib/mocha/state_machine.rb', line 60</span>

<span class='kw'>def</span> <span class='id identifier rubyid_become'>become</span><span class='lparen'>(</span><span class='id identifier rubyid_next_state_name'>next_state_name</span><span class='rparen'>)</span>
  <span class='ivar'>@current_state</span> <span class='op'>=</span> <span class='id identifier rubyid_next_state_name'>next_state_name</span>
<span class='kw'>end</span></pre>
    </td>
  </tr>
</table>
</div>
    
      <div class="method_details ">
  <h3 class="signature " id="is-instance_method">
  
    
      <span class="overload">#<strong>is</strong>(expected_state_name)  &#x21d2; <tt><span class='object_link'><a href="StateMachine/StatePredicate.html" title="Mocha::StateMachine::StatePredicate (class)">StatePredicate</a></span></tt> </span>
    
      <span class="overload">#<strong>is</strong>(desired_state_name)  &#x21d2; <tt><span class='object_link'><a href="StateMachine/State.html" title="Mocha::StateMachine::State (class)">State</a></span></tt> </span>
    
  

  

  
</h3><div class="docstring">
  <div class="discussion">
    
<p>Provides mechanisms to (a) determine whether the <span class='object_link'><a href="" title="Mocha::StateMachine (class)">Mocha::StateMachine</a></span> is in a given state; or (b) to change the <span class='object_link'><a href="" title="Mocha::StateMachine (class)">Mocha::StateMachine</a></span> into the given state.</p>


  </div>
</div>
<div class="tags">
  
  <p class="tag_title">Overloads:</p>
  <ul class="overload">
    
      
      <li class="overload_item">
        <span class="signature">#<strong>is</strong>(expected_state_name)  &#x21d2; <tt><span class='object_link'><a href="StateMachine/StatePredicate.html" title="Mocha::StateMachine::StatePredicate (class)">StatePredicate</a></span></tt> </span>
        <div class="docstring">
  <div class="discussion">
    
<p>Provides a mechanism to determine whether the <span class='object_link'><a href="" title="Mocha::StateMachine (class)">Mocha::StateMachine</a></span> is in the state specified by <code>expected_state_name</code> at some point in the future</p>


  </div>
</div>
<div class="tags">
  <p class="tag_title">Parameters:</p>
<ul class="param">
  
    <li>
      
        <span class='name'>expected_state_name</span>
      
      
        <span class='type'>(<tt>String</tt>)</span>
      
      
      
        &mdash;
        <div class='inline'>
<p>name of expected state.</p>
</div>
      
    </li>
  
</ul>

<p class="tag_title">Returns:</p>
<ul class="return">
  
    <li>
      
      
        <span class='type'>(<tt><span class='object_link'><a href="StateMachine/StatePredicate.html" title="Mocha::StateMachine::StatePredicate (class)">StatePredicate</a></span></tt>)</span>
      
      
      
        &mdash;
        <div class='inline'>
<p>state predicate which, when queried, will indicate whether the <span class='object_link'><a href="" title="Mocha::StateMachine (class)">Mocha::StateMachine</a></span> is in the state specified by <code>expected_state_name</code></p>
</div>
      
    </li>
  
</ul>

</div>
      </li>
    
      
      <li class="overload_item">
        <span class="signature">#<strong>is</strong>(desired_state_name)  &#x21d2; <tt><span class='object_link'><a href="StateMachine/State.html" title="Mocha::StateMachine::State (class)">State</a></span></tt> </span>
        <div class="docstring">
  <div class="discussion">
    
<p>Provides a mechanism to change the <span class='object_link'><a href="" title="Mocha::StateMachine (class)">Mocha::StateMachine</a></span> into the state specified by <code>desired_state_name</code> at some point in the future.</p>


  </div>
</div>
<div class="tags">
  <p class="tag_title">Parameters:</p>
<ul class="param">
  
    <li>
      
        <span class='name'>desired_state_name</span>
      
      
        <span class='type'>(<tt>String</tt>)</span>
      
      
      
        &mdash;
        <div class='inline'>
<p>name of desired new state.</p>
</div>
      
    </li>
  
</ul>

<p class="tag_title">Returns:</p>
<ul class="return">
  
    <li>
      
      
        <span class='type'>(<tt><span class='object_link'><a href="StateMachine/State.html" title="Mocha::StateMachine::State (class)">State</a></span></tt>)</span>
      
      
      
        &mdash;
        <div class='inline'>
<p>state which, when activated, will change the <span class='object_link'><a href="" title="Mocha::StateMachine (class)">Mocha::StateMachine</a></span> into the state with the specified <code>desired_state_name</code>.</p>
</div>
      
    </li>
  
</ul>

</div>
      </li>
    
  </ul>
<p class="tag_title">Parameters:</p>
<ul class="param">
  
    <li>
      
        <span class='name'>state_name</span>
      
      
        <span class='type'>(<tt>String</tt>)</span>
      
      
      
        &mdash;
        <div class='inline'>
<p>name of expected/desired state.</p>
</div>
      
    </li>
  
</ul>

<p class="tag_title">Returns:</p>
<ul class="return">
  
    <li>
      
      
        <span class='type'>(<tt><span class='object_link'><a href="StateMachine/StatePredicate.html" title="Mocha::StateMachine::StatePredicate (class)">StatePredicate</a></span></tt>, <tt><span class='object_link'><a href="StateMachine/State.html" title="Mocha::StateMachine::State (class)">State</a></span></tt>)</span>
      
      
      
        &mdash;
        <div class='inline'>
<p>(a) state predicate which, when queried, will indicate whether the <span class='object_link'><a href="" title="Mocha::StateMachine (class)">Mocha::StateMachine</a></span> is in the given state; or (b) state which, when activated, will change the <span class='object_link'><a href="" title="Mocha::StateMachine (class)">Mocha::StateMachine</a></span> into the given state.</p>
</div>
      
    </li>
  
</ul>

</div><table class="source_code">
  <tr>
    <td>
      <pre class="lines">


78
79
80</pre>
    </td>
    <td>
      <pre class="code"><span class="info file"># File 'lib/mocha/state_machine.rb', line 78</span>

<span class='kw'>def</span> <span class='id identifier rubyid_is'>is</span><span class='lparen'>(</span><span class='id identifier rubyid_state_name'>state_name</span><span class='rparen'>)</span>
  <span class='const'><span class='object_link'><a href="StateMachine/State.html" title="Mocha::StateMachine::State (class)">State</a></span></span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span><span class='lparen'>(</span><span class='kw'>self</span><span class='comma'>,</span> <span class='id identifier rubyid_state_name'>state_name</span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>is</span><span class='tstring_end'>&#39;</span></span><span class='rparen'>)</span> <span class='lbrace'>{</span> <span class='op'>|</span><span class='id identifier rubyid_current'>current</span><span class='comma'>,</span> <span class='id identifier rubyid_given'>given</span><span class='op'>|</span> <span class='id identifier rubyid_current'>current</span> <span class='op'>==</span> <span class='id identifier rubyid_given'>given</span> <span class='rbrace'>}</span>
<span class='kw'>end</span></pre>
    </td>
  </tr>
</table>
</div>
    
      <div class="method_details ">
  <h3 class="signature " id="is_not-instance_method">
  
    #<strong>is_not</strong>(unexpected_state_name)  &#x21d2; <tt><span class='object_link'><a href="StateMachine/StatePredicate.html" title="Mocha::StateMachine::StatePredicate (class)">StatePredicate</a></span></tt> 
  

  

  
</h3><div class="docstring">
  <div class="discussion">
    
<p>Provides a mechanism to determine whether the <span class='object_link'><a href="" title="Mocha::StateMachine (class)">Mocha::StateMachine</a></span> is <strong>not</strong> in the state specified by <code>unexpected_state_name</code> at some point in the future.</p>


  </div>
</div>
<div class="tags">
  <p class="tag_title">Parameters:</p>
<ul class="param">
  
    <li>
      
        <span class='name'>unexpected_state_name</span>
      
      
        <span class='type'>(<tt>String</tt>)</span>
      
      
      
        &mdash;
        <div class='inline'>
<p>name of unexpected state.</p>
</div>
      
    </li>
  
</ul>

<p class="tag_title">Returns:</p>
<ul class="return">
  
    <li>
      
      
        <span class='type'>(<tt><span class='object_link'><a href="StateMachine/StatePredicate.html" title="Mocha::StateMachine::StatePredicate (class)">StatePredicate</a></span></tt>)</span>
      
      
      
        &mdash;
        <div class='inline'>
<p>state predicate which, when queried, will indicate whether the <span class='object_link'><a href="" title="Mocha::StateMachine (class)">Mocha::StateMachine</a></span> is <strong>not</strong> in the state specified by <code>unexpected_state_name</code>.</p>
</div>
      
    </li>
  
</ul>

</div><table class="source_code">
  <tr>
    <td>
      <pre class="lines">


86
87
88</pre>
    </td>
    <td>
      <pre class="code"><span class="info file"># File 'lib/mocha/state_machine.rb', line 86</span>

<span class='kw'>def</span> <span class='id identifier rubyid_is_not'>is_not</span><span class='lparen'>(</span><span class='id identifier rubyid_unexpected_state_name'>unexpected_state_name</span><span class='rparen'>)</span> <span class='comment'># rubocop:disable Naming/PredicatePrefix
</span>  <span class='const'><span class='object_link'><a href="StateMachine/StatePredicate.html" title="Mocha::StateMachine::StatePredicate (class)">StatePredicate</a></span></span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span><span class='lparen'>(</span><span class='kw'>self</span><span class='comma'>,</span> <span class='id identifier rubyid_unexpected_state_name'>unexpected_state_name</span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>is not</span><span class='tstring_end'>&#39;</span></span><span class='rparen'>)</span> <span class='lbrace'>{</span> <span class='op'>|</span><span class='id identifier rubyid_current'>current</span><span class='comma'>,</span> <span class='id identifier rubyid_given'>given</span><span class='op'>|</span> <span class='id identifier rubyid_current'>current</span> <span class='op'>!=</span> <span class='id identifier rubyid_given'>given</span> <span class='rbrace'>}</span>
<span class='kw'>end</span></pre>
    </td>
  </tr>
</table>
</div>
    
      <div class="method_details ">
  <h3 class="signature " id="starts_as-instance_method">
  
    #<strong>starts_as</strong>(initial_state_name)  &#x21d2; <tt><span class='object_link'><a href="" title="Mocha::StateMachine (class)">StateMachine</a></span></tt> 
  

  

  
</h3><div class="docstring">
  <div class="discussion">
    
<p>Put the <span class='object_link'><a href="" title="Mocha::StateMachine (class)">Mocha::StateMachine</a></span> into the state specified by <code>initial_state_name</code>.</p>


  </div>
</div>
<div class="tags">
  <p class="tag_title">Parameters:</p>
<ul class="param">
  
    <li>
      
        <span class='name'>initial_state_name</span>
      
      
        <span class='type'>(<tt>String</tt>)</span>
      
      
      
        &mdash;
        <div class='inline'>
<p>name of initial state</p>
</div>
      
    </li>
  
</ul>

<p class="tag_title">Returns:</p>
<ul class="return">
  
    <li>
      
      
        <span class='type'>(<tt><span class='object_link'><a href="" title="Mocha::StateMachine (class)">StateMachine</a></span></tt>)</span>
      
      
      
        &mdash;
        <div class='inline'>
<p>state machine, thereby allowing invocations of other <span class='object_link'><a href="" title="Mocha::StateMachine (class)">Mocha::StateMachine</a></span> methods to be chained.</p>
</div>
      
    </li>
  
</ul>

</div><table class="source_code">
  <tr>
    <td>
      <pre class="lines">


52
53
54
55</pre>
    </td>
    <td>
      <pre class="code"><span class="info file"># File 'lib/mocha/state_machine.rb', line 52</span>

<span class='kw'>def</span> <span class='id identifier rubyid_starts_as'>starts_as</span><span class='lparen'>(</span><span class='id identifier rubyid_initial_state_name'>initial_state_name</span><span class='rparen'>)</span>
  <span class='id identifier rubyid_become'>become</span><span class='lparen'>(</span><span class='id identifier rubyid_initial_state_name'>initial_state_name</span><span class='rparen'>)</span>
  <span class='kw'>self</span>
<span class='kw'>end</span></pre>
    </td>
  </tr>
</table>
</div>
    
  </div>

</div>

      <div id="footer">
  Generated on Tue Nov 11 14:27:03 2025 by
  <a href="https://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
  0.9.37 (ruby-3.3.0).
</div>

    </div>
  </body>
</html>